
public class CreateDeadLockArray 
{

	private static MoveRule moveRule = new BoxMoveReverseNaiveDeadlockFinder();
	
	public static boolean[][] create( Board board )
	{
		boolean[][] deadlocks = board.getDeadlockArray();
		
		VisitedCellHelper visited = board.getVisitedBoardHelper();
		
		for ( Cord goal : board.getGoals() )
		{
			DFS( board, new MoveImpl( goal ), deadlocks, visited );
		}
		
		return deadlocks;
	}
	
	private static void DFS( Board board, Move currentMove,  boolean[][] deadlocks, VisitedCellHelper visited )
	{
		
//		System.out.println( currentMove.getX() +":"+ currentMove.getY() );
		
		if ( visited.unisitedCell(currentMove) )
		{
			visited.registerCellAsVisited(currentMove);
			
//			if ( ( board.getCellType(currentMove) == Board.CellType.GoalSquare ) ||
//					( board.getCellType(currentMove) == Board.CellType.PlayerOnGoalSquare ) )
//					{
//						return currentMove.getPathToThis();
//					}
					
					for ( Move m : board.getLegalMoves(currentMove, moveRule) )
					{
//						queue.addLast( m );
						DFS( board, m, deadlocks, visited );
					}
			
		}
		else
		{
			deadlocks[ currentMove.getX() ][ currentMove.getY() ] = true;
			// Do nothing
		}
	}
	
}
